import React, { FC,useReducer, useContext } from 'react'
import { TodoContext } from './index.ts'
// import reducer from './reducer.ts'
// import initialState from './store.ts'
const List: FC = ()=>{
    const context = useContext(TodoContext) // 拿到的shi
    const [state,dispatch] = useReducer(reducer,initialState)
    const del = (id: string)=>{
        dispatch({type: 'delete', payload:id})
    }
    return (
        <>
            <ul>
                {state.map(todo =>(
                    <li key={todo.id}>
                        <span>{todo.title}</span>
                        <button onClick={()=> del(todo.id)}>删除</button>
                    </li>
                ))}
            </ul>
        </>
    )
}

export default List
